package com.dolphin.apidriver.service;

import com.dolphin.apidriver.remote.ServiceDriverUserClient;
import com.dolphin.apidriver.remote.ServiceMapClient;
import com.dolphin.common.dto.Car;
import com.dolphin.common.dto.ResponseResult;
import com.dolphin.common.request.ApiDriverPointRequest;
import com.dolphin.common.request.PointRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PointService {

    @Autowired
    private ServiceDriverUserClient serviceDriverUserClient;
    @Autowired
    private ServiceMapClient serviceMapClient;
    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest){
        //读取carId
        Long carId = apiDriverPointRequest.getCarId();


        //通过carID 获取trid、tid，调用 service-driver-user的接口

        ResponseResult<Car> carResponseResult = serviceDriverUserClient.getCarById(carId);
        Car data = carResponseResult.getData();
        String trid = data.getTrid();
        String tid = data.getTid();
        //调用service-map的接口，上传轨迹信息
        PointRequest pointRequest = new PointRequest();
        pointRequest.setTid(tid);
        pointRequest.setTrid(trid);
        pointRequest.setPoints(apiDriverPointRequest.getPoints());
        return serviceMapClient.upload(pointRequest);

    }
}
